package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.atguigu.tingshu.vo.order.TrackPayVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;

    @GuiGuLogin
    @Operation(summary = "批量获取下单付费声音列表")
    @GetMapping("/findPaidTrackInfoList/{trackId}/{trackCount}")
    public Result<List<TrackInfo>> findPaidTrackInfoList(@PathVariable("trackId") Long trackId,@PathVariable("trackCount") Integer trackCount){
        List<TrackInfo> trackInfoList =  trackInfoService.findPaidTrackInfoList(trackId,trackCount);
        return Result.ok(trackInfoList);
    }

    @GuiGuLogin
    @Operation(summary = "获取用户声音分集购买支付列表")
    @GetMapping("/findUserTrackPaidList/{trackId}")
    public Result<List<TrackPayVo>> findUserTrackPaidList(@PathVariable("trackId") Long trackId) {
        List<TrackPayVo> trackPayVoList = trackInfoService.findUserTrackPaidList(trackId);
        return Result.ok(trackPayVoList);
    }

    @Operation(summary = "获取声音统计信息")
    @GetMapping("/getTrackStatVo/{trackId}")
    public Result<TrackStatVo> getTrackStatVo(@PathVariable("trackId") Long trackId) {
        TrackStatVo trackStatVo = trackInfoService.getTrackStatVoByTrackId(trackId);
        return Result.ok(trackStatVo);
    }
    @GuiGuLogin(required = false)
    @Operation(summary = "获取专辑声音分页列表")
    @GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
    public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable("albumId")  Long albumId,
                                                              @PathVariable("page") Integer pageNum,
                                                              @PathVariable("limit") Integer pageSize) {

        IPage<AlbumTrackListVo> trackInfoVoIPage = trackInfoService.findAlbumTrackPage(albumId, pageNum, pageSize);
        return Result.ok(trackInfoVoIPage);
    }

    @Operation(summary = "删除声音信息")
    @DeleteMapping("removeTrackInfo/{id}")
    public Result removeTrackInfo(@PathVariable("id") Long trackId){
        trackInfoService.removeTrackInfo(trackId);
        return Result.ok();
    }

    @Operation(summary = "获取当前用户声音分页列表接口")
    @PostMapping("/findUserTrackPage/{page}/{limit}")
    public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable("page") Integer pageNum,
                                                        @PathVariable("limit") Integer pageSize,
                                                        @RequestBody TrackInfoQuery trackInfoQuery) {

        IPage<TrackListVo> trackListVoIPage = trackInfoService.findUserTrackPage(pageNum, pageSize, trackInfoQuery);
        return Result.ok(trackListVoIPage);
    }

    @Operation(summary = "声音上传接口")
    @PostMapping("/uploadTrack")
    public Result<UploadTrackVo> uploadTrack(MultipartFile file) {
        UploadTrackVo uploadTrackVo = trackInfoService.trackInfoService(file);
        return Result.ok(uploadTrackVo);
    }

    @GuiGuLogin
    @Operation(summary = "新增声音接口")
    @PostMapping("/saveTrackInfo")
    public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
        trackInfoService.saveTrackInfo(trackInfoVo);
        return Result.ok();
    }

    @Operation(summary = "根据ID查询声音信息")
    @GetMapping("/getTrackInfo/{id}")
    public Result<TrackInfo> getTrackInfo(@PathVariable("id") Long trackId) {
        return Result.ok(trackInfoService.getById(trackId));
    }

    @Operation(summary = "修改声音接口")
    @PutMapping("updateTrackInfo/{id}")
    public Result updateTrackInfo(@PathVariable("id") Long trackId,@RequestBody TrackInfoVo trackInfoVo){
        trackInfoService.updateTrackInfo(trackId,trackInfoVo);
        return Result.ok();
    }

}

